<style lang="less">

</style>
<template>
  <div class="tops">
      <div>
        <el-dialog
          :title="csType==0?'用户充值':'用户提现'"
          :visible.sync="dialogVisibles"
          width="30%">
          <div style="padding-left:5rem;">
            <div>
              <img style="width:100px;height:100px;border-radius: 128px;" :src="userInfo.headimgurl || ''" alt="">
            </div>
            <p style="margin-top:10px;">
              昵称： {{userInfo.nickname}}
            </p>
            <p style="margin-top:10px;">
              钻石数： {{getMoney(userInfo.money)}}
            </p>
            <p>
              <el-input style="width:50%;" type="number" v-model.number="customMon" placeholder="请输入充值的钻石数"></el-input>
            </p>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="CSmoney">{{csType==0?'确认充值':'确认提现'}}</el-button>
          </span>
        </el-dialog>


        <el-dialog :title="csType==0?'用户充值':'用户提现'" :visible.sync="dialogVisible">
          <div>
            <el-input v-model="nickname" style="width:250px;padding:5px;" placeholder="请输用户昵称"></el-input>
            &nbsp;&nbsp;
            <el-button type="primary" @click="suosou">搜索</el-button>
          </div>
          <el-table 
            border
            style="margin-top:1rem;"
            :data="userList">
            <el-table-column
              prop="headimgurl"
              width="100"
              align="center"
              label="头像">
              <template slot-scope="scope">
                <img class="headimg" :src="scope.row.headimgurl" />
              </template>
            </el-table-column>
            <el-table-column
              prop="nickname"
              align="center"
              label="昵称">
            </el-table-column>
            <el-table-column
              prop="money"
              align="center"
              label="钻石数">
              <template slot-scope="scope">
                  {{getMoney(scope.row.money)}}
              </template>
            </el-table-column>
            <el-table-column
              prop="creattime"
              align="center"
              label="注册日期">
              <template slot-scope="scope">
                  {{getDay(scope.row.creattime)}}
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              label="操作"
              align="center">
              <template slot-scope="scope">
                <el-button @click="cs(scope.row)" type="text" size="small">{{csType==0?'充值':'提现'}}</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block" style="text-align:center;margin-top:2rem;">
            <el-pagination
              @current-change="userChange"
              :current-page.sync="indexUser"
              :page-size="sizeUser"
              layout="total, prev, pager, next"
              :total="totalUser">
            </el-pagination>
          </div>

        </el-dialog>

        <el-row :gutter="46">
          <el-col :span="12">
            <div class="boxcard">
              <div class="newpeople">
                <div>今日盈利</div>
                <section >
                  {{(collection-transfer).toFixed(2)}}元
                </section>
              </div>
              <div  class="newpeople" style="flex:1;padding-bottom:1px;">
                  <div>今日金额查看</div>
                  <div class="jex">
                    <i class="fa fa-money"></i>今日充值
                    <span><b class="red">
                      {{collection}}</b>元
                      <!-- &nbsp;
                      <el-button @click="csSelect(0)" type="primary">充 值</el-button> -->
                    </span>
                  </div>
                   <div class="jex">
                    <i class="fa fa-eercast"></i>今日提现
                    <span><b class="green">
                      {{transfer}}</b>元
                      <!-- &nbsp;
                      <el-button @click="csSelect(1)" type="success">提 现</el-button> -->
                    </span>
                    
                  </div>
              </div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="boxcard">
               <div class="newpeople" style="flex:1;">
                <div style="margin-bottom:10px;">数据详情信息</div>
                <div class="jext">
                    <i class="fa fa-user-circle"></i>今日成交量
                    <span><b class="red">{{orders}}</b>单</span>
                </div>
                 <div class="jext">
                    <i class="fa fa-user-circle"></i>今日新增用户
                    <span><b>{{createUser}}</b>人</span>
                </div>
                 <div class="jext">
                    <i class="fa fa-user-circle"></i>总用户
                    <span><b>{{visit}}</b>人</span>
                </div>
              </div>
            </div>
          </el-col>
          <el-col :span="4">
             <div class="jexc">
            <p style="padding-top:14px;font-size:18px;">今日推荐用户</p>
            <p style="padding-top:6px;font-weight:bold;">{{master.Threemen}} 人</p>
            </div>
             <div class="jexc">
                <p style="padding-top:14px;font-size:18px;">今日实付佣金</p>
                <p style="padding-top:6px;font-weight:bold;">{{master.Threeorders}} 元</p>
            </div>
          </el-col>
        </el-row>
        <div style="border: 0.1px solid #DDDDDD;margin-bottom:5rem;background-color: #FFFFFF;border-radius: 2px;">
          <h1 style="text-align:center;">平台数据</h1>
          <div style="margin-top:20px;">
            <template>
              <el-table
                :data="tableData"
                stripe
                border
                style="width: 100%">
                <el-table-column
                  prop="time"
                  align="center"
                  label="统计日期">
                  <template slot-scope="scope">
                    {{getDay(scope.row.time)}}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="rechangs"
                  align="center"
                  label="当日充值">
                </el-table-column>
                <el-table-column
                  prop="cashs"
                  align="center"
                  label="当日提现">
                </el-table-column>
                <el-table-column
                  prop="orders"
                  align="center"
                  label="当日成交量">
                </el-table-column>
                <el-table-column
                  prop="addmoneys"
                  align="center"
                  label="当日平台盈利">
                </el-table-column>
                <el-table-column
                  prop="threemoneys"
                  align="center"
                  label="当日佣金">
                </el-table-column>
                <el-table-column
                  prop="users"
                  align="center"
                  label="客户总数">
                </el-table-column>
                <el-table-column
                  prop="todayusers"
                  align="center"
                  label="当日新增客户">
                </el-table-column>
                <el-table-column
                  prop="threes"
                  align="center"
                  label="当日推荐人客户">
                </el-table-column>
                <!-- <el-table-column
                  fixed="right"
                  label="操作"
                  align="center"
                  width="100">
                  <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>
                  </template>
                </el-table-column> -->
              </el-table>
            </template>
          </div>
          <div class="block" style="text-align:center;margin-top:2rem;margin-bottom:2rem;">
            <el-pagination
              background
              @current-change="handleCurrentChange"
              :current-page.sync="index"
              :page-size="size"
              layout="total, prev, pager, next"
              :total="total">
            </el-pagination>
          </div>
        </div>



      </div>
    </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      createUser: 0,
      visit: 0,
      collection: 0,
      transfer: 0,
      tableData: [],
      orders: 0,
      master:{
        Threemen:0,
        Threeorders:0
      },
      total: 0,
      size: 10,
      index: 1,

      dialogVisible: false,
      dialogVisibles: false,
      nickname: '',
      totalUser: 0,
      sizeUser: 5,
      indexUser: 1,
      userList: [],
      csType: 0,
      userInfo: {},
      customMon: null
    };
  },
  computed: {},
  mounted() {
    this.$store.commit("cactive", "home");
    this.userSum();
    this.getData();
  },
  methods: {
    async CSmoney(){
      if(this.customMon!=null&&this.customMon>0){
        this.customMon = this.customMon.toFixed(2);
        if(this.csType==0){
          //充值
          try{
            let parse = {unionid:this.userInfo.unionid,
                      nickname:this.userInfo.nickname,
                      headimgurl:this.userInfo.headimgurl,
                      money:this.customMon };
            let retur = await this.$http.post("/recharge/adminRecharge", parse);
            if(retur.data==1){
              this.$message({
                type: 'success',
                message: '充值成功！'
              });
              this.dialogVisibles = false;
              this.userSum();
            }else{
              this.$message({
                message: '充值失败！'
              });
              this.dialogVisibles = false;
            }
          } catch (error) {
            console.log(error);
            this.$message({
              message: '充值失败！'
            });
            this.dialogVisibles = false;
          }
        }else{
          //提现

          try{
            let parse = {unionid:this.userInfo.unionid,
                      nickname:this.userInfo.nickname,
                      headimgurl:this.userInfo.headimgurl,
                      money:this.customMon };
            let retur = await this.$http.post("/cash/adminCash", parse);
            if(retur.data==1){
              this.$message({
                type: 'success',
                message: '提现成功！'
              });
              this.dialogVisibles = false;
              this.userSum();
            }else{
              this.$message({
                message: '提现失败！'
              });
              this.dialogVisibles = false;
            }
          } catch (error) {
            console.log(error);
            this.$message({
              message: '提现失败！'
            });
            this.dialogVisibles = false;
          }

        }
      }else{
        this.$message({
          message: '金额必须大于0！'
        });
      }
    },
    cs(m){
      this.userInfo = m;
      console.log(this.userInfo)
      this.dialogVisible = false;
      this.dialogVisibles = true;
    },
    csSelect(n){
      this.csType = n;
      this.dialogVisible = true;
      this.indexUser = 1;
      this.customMon = null;
      this.getUserData();
    },
    suosou(){
      this.indexUser = 1;
      this.getUserData();
    },
    userChange: function(page){ 
      this.indexUser = page
      this.getUserData();
    },
    async getUserData(){
      let nickname = this.nickname || "";
      let params = { nickname, page: this.indexUser, size: this.sizeUser };
      try {
        let result = await this.$http.get("/user/getUserSelect", { params });
        this.userList = result.data.data;
        this.totalUser = result.data.total;
      } catch (error) {
        console.log(error);
      }
    },


    async userSum() {
      let orders = await this.$http.get("/order/orderNum");
      this.orders = orders.data;
      let userSum = await this.$http.get("/user/userSum");
      this.visit = userSum.data;
      let userDaySum = await this.$http.get("/user/userDaySum");
      this.createUser = userDaySum.data;
      let master = await this.$http.get("/super/getmaster");
      this.master = master.data;
      let cashDaySum = await this.$http.get("/cash/cashDaySum");
      let rechargeDaySum = await this.$http.get("/recharge/rechargeDaySum");
      this.transfer = cashDaySum.data;
      this.collection = rechargeDaySum.data;
    },
    handleCurrentChange: function(page) {
      this.index = page;
      this.getData();
    },
    getMoney(num) {
      if(num==0){
        return 0
      }else{
        if(num==null){
          return;
        }else{
          return num.toFixed(2);
        }
      }

    },
    getDay(num) {
      let t = new Date(num);
      return (
        t.getFullYear() + "-" + (t.getMonth() + 1) + "-" + t.getDate()
      );
    },
    async getData() {
      let params = { size: this.size, index: this.index  };
      try {
        let result = await this.$http.get("/super/pageTotal", { params });
        this.tableData = result.data.data;
        this.total = result.data.total;
      } catch (error) {
        console.log(error);
      }
    }
  }
};
</script>
